package cn.karent.processor;

import cn.karent.common.JsonUtils;
import cn.karent.common.ValidationUtils;
import io.micrometer.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.GenericTypeResolver;

/**
 * @author wanshengdao
 * @date 2025/3/23
 */
@Slf4j
public abstract class ConfigurableProcessor<C> implements Processor {

    protected C c;

    @SuppressWarnings("unchecked")
    public void config(String str) {
        if (StringUtils.isBlank(str)) {
            log.debug("没有配置项, 不配置");
            return;
        }
        Class<C> clazz = (Class<C>) GenericTypeResolver.resolveTypeArgument(getClass(), ConfigurableProcessor.class);
        c = JsonUtils.parseObject(str, clazz);
        ValidationUtils.valid(c);
    }


}
